package com.katsu.myapplib.secret;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class SecretHmacSHA1 implements Secret<byte[], String> {

    private SecretKeySpec c;

    private Mac m;

    public SecretHmacSHA1(String secretKey) {

        try {

            m = Mac.getInstance("HmacSHA1");

            m.init(c = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1"));

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    @Override
    public byte[] encrypt(String plaintext) {

        try {

            return m.doFinal(plaintext.getBytes("UTF-8"));

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }

    @Override
    public String decrypt(String ciphertext) {

        return ciphertext;

    }

}
